/**
 * 微信iDC商城 － 公共方法集
 * @module wechatMall/idc
 * @author pmkx2 (185832959@qq.com)
 */
define('idc', [], function(){
	//Idc项目公用方法集
	var Idc = function( config ){
	    this.config = $.extend({
	        $root 		: $('body')
	    }, config || {});
	}

	//公共：获取支付方式
	Idc.prototype.getPayWayText = function( code ){
		var payWay = '';
		switch(code){
			//在线支付
			case 'SMW5': payWay = '在线支付'; break;
			//货到付款
			case 'SMW0': payWay = '货到付款'; break;
			//信用支付
			case 'SM14': payWay = '信用支付'; break;
		}
		return payWay;
	};

	//公共：获取订单状态
	Idc.prototype.getOrderStateText = function( code ){
		var state = '';
		switch(code){
			//待支付
			case 'E0000': state = '待支付'; break;
			//待审批
			case 'E0001': state = '订单已提交'; break;
			//已审批
			case 'E0002': state = '订单已提交'; break;
			//已确认
			case 'E0003': state = '订单已提交'; break;
			//订单异常
			case 'E0004': state = '订单已提交'; break;
			//订单取消
			case 'E0005': state = '订单取消'; break;
			//同步SAP失败
			case 'E0010': state = '订单已提交'; break;
			//订单取消失败
			case 'E0011': state = '订单取消失败'; break;
			//取消订单审批中
			case 'E0012': state = '取消订单审批中'; break;
			//首单拦截
			case 'E0090': state = '首单拦截'; break;
		}
		return state;
	};

	//日期方法
	Idc.prototype.fnDate = function(){
		var week = ['日','一','二','三','四','五','六'];
		var fnDate = {
			//获取一个正常日期
			getDate: function( date ){
				if(typeof date === 'string'){ date = date.replace(/-/g,'/'); }
				date = date || new Date();
				var d = new Date(date);
				var sd = d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate();
				return sd;
			},
			//获取全部日期
			getAllDate: function( date ){
				if(typeof date === 'string'){ date = date.replace(/-/g,'/'); }
				date = date || new Date();
				var d = new Date(date);
				var sd = d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate();
				var subDate = (d.getMonth()+1)+'-'+d.getDate();
				var day = d.getDay();
				var allDate = {allDate:d, date:sd, subDate:subDate, week:week[day] };
				return allDate;
			},
			//获取上下一天日期：days：提前的天数，date：对照日期
			getDirDate: function( days, date ){
				if(typeof date === 'string'){ date = date.replace(/-/g,'/'); }
				days = days || 0;
				var dirs = 86400 * days;
				var titleDate = !date ? new Date() : new Date(date);
				var newDate = new Date((titleDate/1000+dirs)*1000);
				return this.getAllDate(newDate);
			}
		};
		return fnDate;
	};

	return Idc;
});